using System;
using System.Collections.Generic;
using System.Text;
using NUnit.Framework;
using Jasongozy.Copor;
using Jasongozy.Copor.Utility;
namespace Copor.Test.UnitTest {
    [TestFixture]
    public class TemplateParameterTest {
        


        [Test]
        public void TemplateParameterStaticInittest() {
            TableSchema schame = new TableSchema();
            schame.TableName = "table1";
            schame.Pks = new string[] { "c1", "c2" };
            schame.Columns = new string[] { "c1", "c2", "c3" };
            schame.ColumnTypes = new string[] { "System.String", "System.String", "System.Int32" };
            schame.DefaultValues = new Dictionary<string, string>();
            schame.DefaultValues.Add("c1", "xxxx1");

            //TemplateParameter param = new TemplateParameter();
            TemplateParameter.InitTemplateParameter(schame, null,null,"Csharp", "mysql", "sqltxt");

            Assert.AreEqual("table1", TemplateParameter.Instance.SampleParams["TableName"]);
            Assert.AreEqual(2, TemplateParameter.Instance.ComplexParams["Pks"].Length);
            Assert.AreEqual("System.String", TemplateParameter.Instance.ComplexParams["ColumnTypes"][1]);
            Assert.AreEqual("xxxx1", TemplateParameter.Instance.SpecialParams["DefaultValues"]["c1"]);
        }


        [Test]
        public void MySqlProcInfoInitTest() {
            string connectionStr = "Server=10.2.6.47;uid=DMClient;pwd=2Fetch(Get;allow zero datetime=no;pooling=true;charset=utf8;database=SupportData;";
            string dbname = "SupportData";
            string procName = "getFundBasicList";
            MySqlProcSchema schema = MySqlDBHelper.GetSqlProcInfo(connectionStr, dbname, procName);
            TemplateParameter.InitTemplateParameter(null, connectionStr, dbname, "CSharp", "MySql", "SqlProc_1");
            TemplateParameter.Instance.AddMySqlProcParams(schema);
            Assert.AreEqual(8, TemplateParameter.Instance.SpecialAryParams[procName].Count);
            Assert.AreEqual(1, TemplateParameter.Instance.SpecialAryParams[procName]["DbType"].Count);
            Console.WriteLine(TemplateParameter.Instance.DisplayProcParams(procName));
        }

        [Test]
        public void MySqlProcInfoInitTest2() {
            string connectionStr = "Server=10.2.6.47;uid=DMClient;pwd=2Fetch(Get;allow zero datetime=no;pooling=true;charset=utf8;database=PeopleData;";
            string dbname = "PeopleData";
            string procName = "getCategoryAverageReturnList";
            MySqlProcSchema schema = MySqlDBHelper.GetSqlProcInfo(connectionStr, dbname, procName);
            TemplateParameter.InitTemplateParameter(null, connectionStr, dbname, "CSharp", "MySql", "SqlProc_1");
            TemplateParameter.Instance.AddMySqlProcParams(schema);
            Assert.AreEqual(8, TemplateParameter.Instance.SpecialAryParams[procName].Count);
            Assert.AreEqual(7, TemplateParameter.Instance.SpecialAryParams[procName]["DbType"].Count);
            Console.WriteLine(TemplateParameter.Instance.DisplayProcParams(procName));
        }
    }
}
